package edu.luas.digitalmedia.controller;

import edu.luas.digitalmedia.pojo.MyAddress;
import edu.luas.digitalmedia.service.MyAddressService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/address/selectOne")
public class MyAddressSelectOneController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.设置请求编码
        req.setCharacterEncoding("UTF-8");
        //2:设置响应编码
        resp.setContentType("text/html;charset=utf-8");
        //3:获取请求信息
        Integer id = Integer.parseInt(req.getParameter("id"));
        MyAddress model = new MyAddressService().selectOne(id);
        //4:将model保存到请求域
        req.setAttribute("model", model);
        //5:控制页面跳转
        req.getRequestDispatcher("/edit.jsp").forward(req,resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
